using MicroMsg.UI.UserContrl;
using Microsoft.Phone.Data.Linq.Mapping;
using System;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Text;
namespace MicroMsg.Storage
{
	[Index(Columns = "nMsgSvrID", IsUnique = false, Name = "nMsgSvrIDIndex"), Index(Columns = "strTalker", IsUnique = false, Name = "strTalker"), Table]
	public class ChatMsg : StorageItem, IListDataItem
	{
		public const uint Field_nMsgLocalID = 1u;
		public const uint Field_nMsgSvrID = 2u;
		public const uint Field_nMsgType = 4u;
		public const uint Field_nStatus = 8u;
		public const uint Field_nIsSender = 16u;
		public const uint Field_nCreateTime = 32u;
		public const uint Field_strTalker = 64u;
		public const uint Field_strContent = 128u;
		public const uint Field_strClientMsgId = 256u;
		public const uint Field_bytesXmlData = 512u;
		public const uint Field_bytesContent = 2048u;
		private int _nMsgLocalID;
		private int _nMsgSvrID;
		private int _nMsgType;
		private int _nStatus;
		private int _nIsSender;
		private long _nCreateTime;
		private string _strTalker;
		private string _strContent;
		private string _strClientMsgId;
		private byte[] _bytesXmlData;
		private byte[] _bytesContent;
		[Column(IsVersion = true)]
		private Binary _version;
		private MsgXmlData _xmlData;
		[Column(IsPrimaryKey = true)]
		public int nMsgLocalID
		{
			get
			{
				return this._nMsgLocalID;
			}
			set
			{
				this._nMsgLocalID = value;
				this.modify |= 1L;
			}
		}
		[Column]
		public int nMsgSvrID
		{
			get
			{
				return this._nMsgSvrID;
			}
			set
			{
				this._nMsgSvrID = value;
				this.modify |= 2L;
			}
		}
		[Column]
		public int nMsgType
		{
			get
			{
				return this._nMsgType;
			}
			set
			{
				this._nMsgType = value;
				this.modify |= 4L;
			}
		}
		[Column]
		public int nStatus
		{
			get
			{
				return this._nStatus;
			}
			set
			{
				this._nStatus = value;
				this.modify |= 8L;
			}
		}
		[Column]
		public int nIsSender
		{
			get
			{
				return this._nIsSender;
			}
			set
			{
				this._nIsSender = value;
				this.modify |= 16L;
			}
		}
		[Column]
		public long nCreateTime
		{
			get
			{
				return this._nCreateTime;
			}
			set
			{
				this._nCreateTime = value;
				this.modify |= 32L;
			}
		}
		[Column]
		public string strTalker
		{
			get
			{
				return this._strTalker;
			}
			set
			{
				this._strTalker = value;
				this.modify |= 64L;
			}
		}
		[Column]
		public string strContent
		{
			get
			{
				return this._strContent;
			}
			set
			{
				this._strContent = value;
				this.modify |= 128L;
			}
		}
		[Column]
		public string strClientMsgId
		{
			get
			{
				return this._strClientMsgId;
			}
			set
			{
				this._strClientMsgId = value;
				this.modify |= 256L;
			}
		}
		[Column]
		public byte[] bytesXmlData
		{
			get
			{
				return this._bytesXmlData;
			}
			set
			{
				this._bytesXmlData = value;
				this.modify |= 512L;
			}
		}
		[Column(DbType = "Image")]
		public byte[] bytesContent
		{
			get
			{
				return this._bytesContent;
			}
			set
			{
				this._bytesContent = value;
				this.modify |= 2048L;
			}
		}
		public string strMsg
		{
			get
			{
				if (this.bytesContent != null)
				{
					return Encoding.get_UTF8().GetString(this.bytesContent, 0, this.bytesContent.Length);
				}
				return this.strContent;
			}
			set
			{
				if (value == null)
				{
					this.strContent = null;
					this.bytesContent = null;
					return;
				}
				if (value.get_Length() <= 3000)
				{
					this.strContent = value;
					this.bytesContent = null;
					return;
				}
				this.strContent = null;
				this.bytesContent = Encoding.get_UTF8().GetBytes(value);
			}
		}
		public string strThumbnail
		{
			get
			{
				this.load();
				return this._xmlData.strThumbnail;
			}
			set
			{
				this.load();
				this._xmlData.strThumbnail = value;
				this.unload();
			}
		}
		public string strPath
		{
			get
			{
				this.load();
				return this._xmlData.strImagePath;
			}
			set
			{
				this.load();
				this._xmlData.strImagePath = value;
				this.unload();
			}
		}
		public bool isVoiceRead
		{
			get
			{
				this.load();
				return this._xmlData.isVoiceRead;
			}
			set
			{
				this.load();
				this._xmlData.isVoiceRead = value;
				this.unload();
			}
		}
		public bool isGifRead
		{
			get
			{
				this.load();
				return this._xmlData.isGifRead;
			}
			set
			{
				this.load();
				this._xmlData.isGifRead = value;
				this.unload();
			}
		}
		public override void merge(object object_0)
		{
			ChatMsg chatMsg = object_0 as ChatMsg;
			if (0L != (chatMsg.modify & 2L))
			{
				this._nMsgSvrID = chatMsg._nMsgSvrID;
			}
			if (0L != (chatMsg.modify & 4L))
			{
				this._nMsgType = chatMsg._nMsgType;
			}
			if (0L != (chatMsg.modify & 8L))
			{
				this._nStatus = chatMsg._nStatus;
			}
			if (0L != (chatMsg.modify & 16L))
			{
				this._nIsSender = chatMsg._nIsSender;
			}
			if (0L != (chatMsg.modify & 32L))
			{
				this._nCreateTime = chatMsg._nCreateTime;
			}
			if (0L != (chatMsg.modify & 64L))
			{
				this._strTalker = chatMsg._strTalker;
			}
			if (0L != (chatMsg.modify & 128L))
			{
				this._strContent = chatMsg._strContent;
			}
			if (0L != (chatMsg.modify & 256L))
			{
				this._strClientMsgId = chatMsg._strClientMsgId;
			}
			if (0L != (chatMsg.modify & 2048L))
			{
				this._bytesContent = chatMsg._bytesContent;
			}
			if (0L != (chatMsg.modify & 512L))
			{
				this._bytesXmlData = chatMsg._bytesXmlData;
				this._xmlData = null;
			}
		}
		public void FillData(object item)
		{
			ChatMsg chatMsg = item as ChatMsg;
			if (chatMsg == null)
			{
				return;
			}
			chatMsg.nMsgLocalID = this.nMsgLocalID;
			chatMsg.nMsgSvrID = this.nMsgSvrID;
			chatMsg.nMsgType = this.nMsgType;
			chatMsg.nStatus = this.nStatus;
			chatMsg.nIsSender = this.nIsSender;
			chatMsg.nCreateTime = this.nCreateTime;
			chatMsg.strTalker = this.strTalker;
			chatMsg.strContent = this.strContent;
			chatMsg.strClientMsgId = this.strClientMsgId;
			chatMsg.bytesXmlData = this.bytesXmlData;
			chatMsg.bytesContent = this.bytesContent;
		}
		private void load()
		{
			if (this._xmlData != null)
			{
				return;
			}
			this._xmlData = StorageXml.loadFromBuffer<MsgXmlData>(this.bytesXmlData);
			if (this._xmlData == null)
			{
				this._xmlData = new MsgXmlData();
			}
		}
		private void unload()
		{
			if (this._xmlData == null)
			{
				return;
			}
			this.bytesXmlData = StorageXml.saveToBuffer<MsgXmlData>(this._xmlData);
		}
	}
}
